package com.andorid.settings.fuelgauge;

import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CompoundButton;
import android.widget.SeekBar;
import android.widget.Switch;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

public class PowerLowModeActivity extends Activity implements OnClickListener {

	private SeekBar mSeekBar;
	private TextView mBatteryPercentage;
	private Switch mSwitch;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.power_low_mode_layout);
		this.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
		this.getActionBar().setCustomView(R.layout.custom_actionbar);
		this.getActionBar().getCustomView().findViewById(R.id.back).setOnClickListener(this);
		TextView title = (TextView) this.getActionBar().getCustomView().findViewById(R.id.title);
		title.setText(getString(R.string.power_saving_low_power_mode));

		mSwitch = (Switch) this.getActionBar().getCustomView().findViewById(R.id.switch1);
		mSwitch.setOnCheckedChangeListener(mSwitchChangeListener);

		mBatteryPercentage = (TextView) super.findViewById(R.id.battery_percentage);
		mSeekBar = (SeekBar) super.findViewById(R.id.seekBar1);
		mSeekBar.setOnSeekBarChangeListener(mOnSeekBarChangeListener);
		
		updateStatus();
	}

	private void updateStatus() {
		Log.d("xue", "sss:"+mSwitch.isEnabled());
		if (mSwitch.isEnabled()) {
			mSeekBar.setEnabled(true);
			mBatteryPercentage.setEnabled(true);
		} else {
			mSeekBar.setEnabled(false);
			mBatteryPercentage.setEnabled(false);
		}
	}

	private OnCheckedChangeListener mSwitchChangeListener = new OnCheckedChangeListener() {

		@Override
		public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
			// TODO Auto-generated method stub
			mSeekBar.setEnabled(isChecked);
			mBatteryPercentage.setEnabled(isChecked);
		}

	};

	private OnSeekBarChangeListener mOnSeekBarChangeListener = new OnSeekBarChangeListener() {

		@Override
		public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
			// TODO Auto-generated method stub
			mBatteryPercentage.setText(progress + "%");
		}

		@Override
		public void onStartTrackingTouch(SeekBar seekBar) {
			// TODO Auto-generated method stub

		}

		@Override
		public void onStopTrackingTouch(SeekBar seekBar) {
			// TODO Auto-generated method stub
			int value = seekBar.getProgress();
		}

	};

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (v.getId() == R.id.back) {
			finish();
		}
	}

}
